//@ts-nocheck
import "./public-path";
import { createApp } from "vue";
import App from "./App.vue";
import "./utils/router";
import ElementPlus from "element-plus";
import "element-plus/dist/index.css";
import "dayjs/locale/zh-cn";
import zhCn from "element-plus/es/locale/lang/zh-cn";
import "@/icons/iconfont/iconfont.css";
import "@/icons/iconfont/iconfont.js";
import "@/styles/main.css";
import LayoutStore from "@/layouts";
import http from "@/api/http";
import { registerComponents } from "./components";
import * as Icons from "@element-plus/icons";
import pinia from "./store/pinia";
import router from "./router";
import { history } from "./router";
import "./setting";

let app = null;

function render(props = {}) {
  const { container } = props;
  const app = createApp(App);
  Object.keys(Icons).forEach((it) => {
    app.component(it, (Icons as any)[it]);
  });
  registerComponents(app);
  app.use(LayoutStore, {
    state: {
      layoutMode: "ltr",
    },
    actions: {
      onPersonalCenter() {
        router.push({ path: "/personal", query: { uid: 1 } });
      },
      onLogout() {
        router.replace({ path: "/login", query: { redirect: "/" } }).then(() => {
          window.location.reload();
        });
      },
    },
  });
  app.use(pinia).use(router);
  app.use(ElementPlus, {
    locale: zhCn,
  });
  app.use(http);
  app.mount(container ? container.querySelector('#app') : "#app");
}
if (!window.__POWERED_BY_QIANKUN__) {
  render();
}

export async function bootstrap() {
  console.log('%c%s', 'color: green;', 'vue3.0 app bootstraped');
}


export async function mount(props) {
  render(props);
}

export async function unmount() {
  console.log('已卸载');
  app.unmount();
  app._container.innerHTML = '';
  app = null;
  router = null;
  history.destroy();
}

